#!/bin/sh
#
# Run a simple backup
#   then verify the catalog.
#
TestName="verify-vol-test"
JobName=VerifyVol
. scripts/functions

scripts/cleanup
scripts/copy-test-confs

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


#
# Add this back when verify can handle sparse files
#  the same way that backup does
#
#scripts/create_sparse_file.sh ${BackupDirectory}/sparsefile 10M

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >tmp/bconcmds
@$out /dev/null
messages
@$out tmp/log1.out
setdebug level=1 storage=File sd
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
@#
@# now do a verify volume
@#
@$out ${cwd}/tmp/log2.out
setdebug level=12 dir
run job=VerifyVolume
yes
wait
messages
@$out ${cwd}/tmp/log3.out
run job=VerifyVolume level=DiskToCatalog
yes
wait
messages
quit
END_OF_DATA

#
#  ***FIXME***
# Note, add sparse file backup and check that checksum is
#  correct.  Bug #1140
#  create sparse file
#  dd if=/dev/zero of=sparsefile bs=1 count=0 seek=10M
#

run_susan

sleep 2
check_for_zombie_jobs storage=File
stop_susan

grep "^  Termination: *Backup OK" tmp/log1.out 2>&1 >/dev/null
bstat=$?
grep "^  Termination: *Verify OK" tmp/log2.out 2>&1 >/dev/null
rstat=$?
if test $rstat=0; then
   grep "^  Termination: *Verify OK" tmp/log3.out 2>&1 >/dev/null
   rstat=$?
fi
dstat=0
end_test
